// 引入连接池
var dbConfig = require('../util/dbconfig')
// 获取分类
getCate = (req, res) => {
  let sql = "SELECT * FROM cate";
  let sqlArr = [];
  let callback = (err, data) => {
    if (err) {
      console.log('pool fail');
    } else {
      res.send(data)
    }
  }
  dbConfig.sqlConnect(sql, sqlArr, callback)
}

// 获取指定分类的文章列表
// http://localhost:3000/getPostCate?id=1
getPostCate = (req, res) => {
  // let { id } = req.query;
  let sql = "SELECT * FROM post WHERE cate_id=?";
  let sqlArr = [req.query.id];
  let callback = (err, data) => {
    if (err) {
      console.log('pool fail');
    } else {
      res.send(data)
    }
  }
  dbConfig.sqlConnect(sql, sqlArr, callback)
}

// 暴露封装
module.exports = {
  getCate,
  getPostCate
};